﻿

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using StockUI.Model;
using StockUI.Views;
using System.Collections.ObjectModel;
using System.Windows.Controls;

namespace StockUI.ViewModels
{
    /// <summary>
    /// 持股分析
    /// </summary>
  public partial class CgfxViewModel : ObservableObject
    {
        [ObservableProperty]
        private ObservableCollection<StockModel> stockItem;

        [ObservableProperty]
        private ObservableCollection<TabItem> tabsItem;

        [ObservableProperty]
        private TabItem selectedTabs;
        public CgfxViewModel()
        {
            StockItem = new ObservableCollection<StockModel>
            {
                new StockModel{Title = "中粮科工",Code = "01"},
                new StockModel{ Title = "赛托生物", Code = "02"},
                new StockModel{ Title = "奥晒科技", Code = "03"}
            };

            //SelectedTabs = new TabItem { Header = "今日复盘", Tag = "Home", Content = new Home() };
            TabsItem = new ObservableCollection<TabItem>
            {
            };
        }
        [RelayCommand]
        private async Task AddItem(object item)
        {
            var addmodel = item as StockModel;
            SelectedTabs = new TabItem { Header = addmodel.Title, Tag = addmodel.Code, Content = new TabCommon() };
            TabsItem.Add(SelectedTabs);
        }


        /// <summary>
        /// 移除命令
        /// </summary>
        [RelayCommand]
        private async Task RemoveItem(TabItem poetry)
        {
            var tab = TabsItem.Where(a => a.Tag == poetry.Tag).First();
            TabsItem.Remove(tab);
        }
    }
    
}
